package com.baitiaojun.mybatisplus.core.basemapper;

import com.baitiaojun.common.domain.model.page.PageParam;
import com.baitiaojun.common.domain.model.result.PageResult;
import com.baitiaojun.common.domain.model.page.PageSorted;
import com.baitiaojun.mybatisplus.core.utils.MybatisUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.Collection;

/**
 * mybatisplus接口扩展
 */
public interface MyBaseMapper<T> extends BaseMapper<T> {

    /**
     * 自定义分页实现
     * @param pageParam
     * @param pageSorted
     * @param queryWrapper
     * @return
     */
    default PageResult<T> selectPage(PageParam pageParam, Collection<PageSorted> pageSorted, LambdaQueryWrapper<T> queryWrapper) {
        Page<T> page = selectPage(MybatisUtils.buildPage(pageParam, pageSorted), queryWrapper);
        return new PageResult<>(page.getTotal(), page.getRecords());
    }
}
